/* 爆客码——设备管理 */
import request from "@/utils/request";
import {object2Url} from "@/utils/trans";

// 爆店码查询设备——单独加接口
export async function getByUndistributed(merchantId) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    merchantId:merchantId,
  };
  let url = `/Equipment/getByUndistributed${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//查询设备
export async function equipmentQuery(data) {
  const res = await request.post('/business/Equipment/page', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 开启设备
export async function equipmentOpen(activityType) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    uid:4,
    key:"ASB12992244",
    activityType:activityType
  };
  let url = `/business/Equipment/open${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 关闭设备
export async function equipmentClose(activityType) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    uid:4,
    key:"ASB12992244",
    activityType:activityType
  };
  let url = `/business/Equipment/close${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

